"""
#!!===========================================================
#版权（C）2023, Huawei Technologies Co., HUTAF xDevice
#!!===========================================================
#用例编号:      Security_IAM_AuthWidget_Fingerprint_Auth_Func_0043
#用例名称:      单指纹认证失败后单指纹冻结
#用例作者:
#修改说明:
#!!===========================================================
"""

# -*- coding: utf-8 -*-
from devicetest.core.test_case import TestCase
from devicetest.aw.OpenHarmony import CommonOH
from aw.Useriam.AuthWidget import SecurityUserIamAuthWidgetHap
from aw.Useriam.AuthWidget import SecurityUserIamFingerPrintAuthApi


class Security_IAM_AuthWidget_Fingerprint_Auth_Func_0043(TestCase):

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        self.tests = [
            "setup",
            "test_step",
            "teardown"
        ]
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        print("预置工作：初始化手机开始............" + self.devices[0].device_sn)
        print("预置工作：录入指纹")
        CommonOH.wake(self.device1)
        SecurityUserIamAuthWidgetHap.setfingerprint(self.device1)
        CommonOH.goHome(self.device1)
        print("预置工作：认证失败4次")
        SecurityUserIamAuthWidgetHap.setAPI(self.device1, 0)
        SecurityUserIamAuthWidgetHap.setAuthType(self.device1, "2", "10000", "指纹认证", " ", "1")
        SecurityUserIamAuthWidgetHap.auth(self.device1, 0)
        SecurityUserIamFingerPrintAuthApi.fingerprintAuth(self.device1, 1)
        SecurityUserIamFingerPrintAuthApi.retryfingerprintAuth(self.device1,1)
        SecurityUserIamFingerPrintAuthApi.retryfingerprintAuth(self.device1, 1)
        SecurityUserIamFingerPrintAuthApi.retryfingerprintAuth(self.device1, 1)
        CommonOH.goHome(self.device1)

    def test_step(self):
        print("测试步骤1：测试hap拉起口令认证")
        SecurityUserIamAuthWidgetHap.setAPI(self.device1, 0)
        SecurityUserIamAuthWidgetHap.setAuthType(self.device1, "2", "10000", "指纹认证", " ", "1")
        SecurityUserIamAuthWidgetHap.auth(self.device1, 0)
        print("测试步骤2：使用错误指纹")
        SecurityUserIamFingerPrintAuthApi.fingerprintAuth(self.device1, 1)
        print("检查点2：认证锁定，控件存在")
        CommonOH.checkIfTextExist(self.device1, "指纹已禁用,请输入密码", expect = True)

    def teardown(self):
        print("收尾工作：删除指纹............")
        SecurityUserIamAuthWidgetHap.deletefingerprint(self.device1)
        print("收尾工作：指纹已删除............")
        SecurityUserIamAuthWidgetHap.setAPI(self.device1, 0)
        SecurityUserIamAuthWidgetHap.setAuthType(self.device1, "2", "10000", "指纹认证", " ", "1")
        SecurityUserIamAuthWidgetHap.auth(self.device1, 0)
        CommonOH.checkIfTextExist(self.device1, "", expect = True)
        print("收尾工作：回到桌面............")
        CommonOH.goHome(self.device1)